package com.scau.action;

import java.util.List;

import net.sf.json.JSONArray;

import com.scau.service.IEmplCateService;
import com.scau.vo.EmployeeCategory;

/**
 * @author Jinglun
 * @create 2017年4月19日
 */
public class EmplCateAction {
	private String result;// 属性result，用于异步传输数据交互
	
	private IEmplCateService emplCateService;
	private EmployeeCategory employeeCategory;
	
	public String saveEmplCate() {
		EmployeeCategory ec = getEmployeeCategory();
		if (emplCateService.saveEmplCate(ec)) {
			// 查出所有员工类型
			List<EmployeeCategory> ecList = emplCateService.listEmplCate();
			JSONArray jsonArray = JSONArray.fromObject(ecList.toString());
			result = jsonArray.toString();
			return "success";
		} else
			return "error";
	}

	public String listEmplCate() {
		List<EmployeeCategory> ecList = emplCateService.listEmplCate();
		JSONArray jsonArray = JSONArray.fromObject(ecList.toString());
		result = jsonArray.toString();
		return "success";
	}
	
	public String deleteEmplCate() {
		EmployeeCategory ec = getEmployeeCategory();

		if (emplCateService.deleteEmplCate(ec.getId())) {
			List<EmployeeCategory> ecList = emplCateService.listEmplCate();
			JSONArray jsonArray = JSONArray.fromObject(ecList.toString());
			result = jsonArray.toString();
			return "success";
		} else
			return "error";
	}

	public String updateEmplCate() {
		EmployeeCategory upEC = getEmployeeCategory();

		if (emplCateService.updateEmplCate(upEC)) {
			List<EmployeeCategory> ecList = emplCateService.listEmplCate();
			JSONArray jsonArray = JSONArray.fromObject(ecList.toString());
			result = jsonArray.toString();
			return "success";
		} else
			return "error";
	}
	
	
	// get,set方法
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public IEmplCateService getEmplCateService() {
		return emplCateService;
	}
	public void setEmplCateService(IEmplCateService emplCateService) {
		this.emplCateService = emplCateService;
	}
	public EmployeeCategory getEmployeeCategory() {
		return employeeCategory;
	}
	public void setEmployeeCategory(EmployeeCategory employeeCategory) {
		this.employeeCategory = employeeCategory;
	}
	
	
}
